package com.ktgj.customer.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ktgj.customer.domain.MallOrderBackstage;
import com.ktgj.customer.domain.MallOrderSearch;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ktgj.common.log.annotation.Log;
import com.ktgj.common.log.enums.BusinessType;
import com.ktgj.common.security.annotation.PreAuthorize;
import com.ktgj.customer.domain.MallOrderRefund;
import com.ktgj.customer.service.IMallOrderRefundService;
import com.ktgj.common.core.web.controller.BaseController;
import com.ktgj.common.core.web.domain.AjaxResult;
import com.ktgj.common.core.utils.poi.ExcelUtil;
import com.ktgj.common.core.web.page.TableDataInfo;

/**
 * 退单Controller
 * 
 * @author ruoyi
 * @date 2022-11-15
 */
@RestController
@RequestMapping("/mallOrderRefund")
public class MallOrderRefundController extends BaseController
{
    @Autowired
    private IMallOrderRefundService mallOrderRefundService;

    /**
     * 查询退单列表
     */
    @PreAuthorize(hasPermi = "customer:refund:list")
    @GetMapping("/list")
    public TableDataInfo list(MallOrderRefund mallOrderRefund)
    {
        startPage();
        List<MallOrderRefund> list = mallOrderRefundService.selectMallOrderRefundList(mallOrderRefund);
        return getDataTable(list);
    }

    /**
     * 导出退单列表
     */
    @PreAuthorize(hasPermi = "customer:refund:export")
    @Log(title = "退单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MallOrderRefund mallOrderRefund) throws IOException
    {
        List<MallOrderRefund> list = mallOrderRefundService.selectMallOrderRefundList(mallOrderRefund);
        ExcelUtil<MallOrderRefund> util = new ExcelUtil<MallOrderRefund>(MallOrderRefund.class);
        util.exportExcel(response, list, "退单数据");
    }

    /**
     * 获取退单详细信息
     */
    @PreAuthorize(hasPermi = "customer:refund:query")
    @GetMapping(value = "/{refundId}")
    public AjaxResult getInfo(@PathVariable("refundId") Long refundId)
    {
        return AjaxResult.success(mallOrderRefundService.selectMallOrderRefundById(refundId));
    }

    /**
     * 新增退单
     */
    @PreAuthorize(hasPermi = "customer:refund:add")
    @Log(title = "退单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MallOrderRefund mallOrderRefund)
    {
        return toAjax(mallOrderRefundService.insertMallOrderRefund(mallOrderRefund));
    }

    /**
     * 修改退单
     */
    //@PreAuthorize(hasPermi = "customer:refund:edit")
    @Log(title = "退单", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody MallOrderRefund mallOrderRefund)
    {
        return toAjax(mallOrderRefundService.updateMallOrderRefund(mallOrderRefund));
    }

    /**
     * 删除退单
     */
    @PreAuthorize(hasPermi = "customer:refund:remove")
    @Log(title = "退单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{refundIds}")
    public AjaxResult remove(@PathVariable Long[] refundIds)
    {
        return toAjax(mallOrderRefundService.deleteMallOrderRefundByIds(refundIds));
    }

    /**
     * 商城退单列表
     * @param search
     * @return
     */
    @PostMapping("/queryMallOrderRefunds")
    public TableDataInfo queryMallOrderRefunds(@RequestBody MallOrderSearch search) {
        startPage();
        List<MallOrderBackstage> mallOrderRefunds = mallOrderRefundService.queryMallOrderRefunds(search);
        return getDataTable(mallOrderRefunds);
    }
}
